Skip to content

Add TLimmuno2 class-II (CD4) immunogenicity predictor (#249) - #252

Merged
iskandr merged 1 commit into
masterfrom
add-tlimmuno2-class2-immunogenicity
Jul 10, 2026
Merged

Add TLimmuno2 class-II (CD4) immunogenicity predictor (#249)#252
iskandr merged 1 commit into
masterfrom
add-tlimmuno2-class2-immunogenicity

Conversation

@iskandr

@iskandr iskandr commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Closes #249.

Adds TLimmuno2 (Wang et al., Briefings in Bioinformatics 2023) — a transfer-learned model for class-II (CD4+) peptide immunogenicity. It's the first class-II immunogenicity predictor in mhctools; Calis, PRIME, BigMHC_IM, and DeepImmuno are all class-I / CD8, so this fills a real gap in the taxonomy. Emits one Kind.immunogenicity prediction per (peptide, allele).

Design

  • Subprocess + sidecar interpreter, wrap-don't-vendor. TLimmuno2 ships weights in-repo but loads them with a Keras 2 / TensorFlow stack, and its license is ambiguous (Apache-2.0 README badge, no LICENSE file) — so mhctools does not vendor it. The wrapper shells out to Python/TLimmuno2.py in a user-provided checkout (TLIMMUNO2_HOME) via a user-provided interpreter (TLIMMUNO2_PYTHON). On newer TensorFlow the interpreter only needs the tf-keras shim; the wrapper sets TF_USE_LEGACY_KERAS=1 for the subprocess so the Keras-2 SavedModels load.
  • Class-II allele handling. Native NetMHCIIpan keys pass through (DRB1_0803, HLA-DPA10103-DPB10101, H-2-IAb); common DR forms convert (HLA-DRB1*08:03DRB1_0803); the mhctools-canonical DRA/DRB pair collapses to its beta chain. TLimmuno2's file mode inner-joins on allele and silently drops unknowns, so the wrapper validates against the checkout's own pseudosequence list and fails loudly instead.
  • Surfaces both score (0–1, higher = more immunogenic) and percentile_rank (TLimmuno2's %Rank, rescaled 0–1 → 0–100, lower = more immunogenic).
  • 21-residue hard peptide cap (the (21,21) encoder limit).

⚠️ Cost

TLimmuno2's %Rank is computed against ~90,000 background peptides per distinct allele, so a call takes ~a minute per allele regardless of how many peptides you pass. Documented in the docstring, README, and a logger.info when >1 allele. (The end-to-end test takes ~5 min for this reason and is gated on TLIMMUNO2_HOME.)

Verification

Confirmed end-to-end against a local TLimmuno2 checkout on TF 2.17 + tf-keras: FHTMWHVTRGAVLMY/DRB1_0803 = 0.9874 (%Rank 0.19). Offline tests (parser, allele-mapping, construction/validation) run in CI. ruff clean.

Same field caveat as the other immunogenicity models, and class-II is noisier still: a prioritization aid, not ground truth.

Version bump 3.30.0 → 3.31.0.

https://claude.ai/code/session_01LZahFhBSCiehXTESCYQ7wG

TLimmuno2 (Wang et al., Briefings in Bioinformatics 2023) is a transfer-learned
model that scores class-II peptide immunogenicity to CD4+ T cells. It is the
first class-II immunogenicity predictor in mhctools — Calis, PRIME, BigMHC_IM,
and DeepImmuno are all class-I / CD8 — so it fills a real gap in the taxonomy,
emitting one Kind.immunogenicity prediction per (peptide, allele).

TLimmuno2 ships weights in-repo but loads them with a Keras 2 / TensorFlow
stack, and its upstream license is ambiguous (an Apache-2.0 README badge with
no LICENSE file), so mhctools does NOT vendor it: the wrapper shells out to its
Python/TLimmuno2.py CLI in a user-provided checkout (TLIMMUNO2_HOME) via a
user-provided interpreter (TLIMMUNO2_PYTHON) — the DeepImmuno/DeepTAP pattern.
On newer TensorFlow the interpreter only needs the tf-keras shim; the wrapper
sets TF_USE_LEGACY_KERAS=1 for the subprocess so the Keras-2 SavedModels load.

- class-II allele handling: native NetMHCIIpan keys pass through (DRB1_0803,
  HLA-DPA10103-DPB10101, H-2-IAb); common DR forms convert; the mhctools
  canonical DRA/DRB pair collapses to the beta chain. TLimmuno2's file mode
  inner-joins on allele and silently drops unknowns, so we validate against its
  own pseudosequence list and fail loudly instead.
- surfaces both the raw score and the %Rank (rescaled 0-1 -> 0-100,
  lower = more immunogenic). %Rank is scored against ~90k background peptides
  per distinct allele, so a call costs ~a minute per allele — documented.
- 21-residue hard peptide cap (the (21,21) encoder limit); reject longer.
- register as "tlimmuno2" in the CLI; export from the package
- tests: parser + allele-mapping + construction/validation offline, end-to-end
  gated on TLIMMUNO2_HOME (verified locally: FHTMWHVTRGAVLMY/DRB1_0803 = 0.9874)
- README + kind_support table; bump 3.30.0 -> 3.31.0

Verified end-to-end against a local TLimmuno2 checkout on TF 2.17 + tf-keras.

Claude-Session: https://claude.ai/code/session_01LZahFhBSCiehXTESCYQ7wG
@iskandr
iskandr merged commit ea02174 into master Jul 10, 2026
5 checks passed
@iskandr
iskandr deleted the add-tlimmuno2-class2-immunogenicity branch July 10, 2026 16:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add TLimmuno2 wrapper — MHC class-II (CD4) immunogenicity

1 participant